package com.example.yz.happywoker.HistoryOrderActivity;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.avos.avoscloud.AVObject;
import com.example.yz.happywoker.R;

import java.util.List;
import java.util.Map;

/**
 * Created by wangcheng on 2017/6/19.
 */

public class MyAdapter extends BaseAdapter {

    private  List<Map<String, Object>> list;
    private LayoutInflater layoutInflater;

    public MyAdapter(Context context,  List<Map<String, Object>> list) {
        super();
        this.list = list;
        //  this.layoutInflater=LayoutInflater.from(context);
        layoutInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }


    /**
     * 组件集合，对应list.xml中的控件
     *
     * @author Administrator
     */
    class Zujian {
        public TextView title;
        public TextView state;
        public TextView date;
        public TextView address;
        public TextView workContent;
    }

    @Override
    public int getCount() {
        return list.size();//根据他的返回值得到listView的长度

    }

    /**
     * 获得某一位置的数据
     */
    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    /**
     * 获得唯一标识
     */
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        Zujian zujian = null;

        if (convertView == null) {
            zujian = new Zujian();
            //获得组件，实例化组件
            convertView = layoutInflater.inflate(R.layout.list, null);
            zujian.state = (TextView) convertView.findViewById(R.id.state);
            zujian.title = (TextView) convertView.findViewById(R.id.titlelist);
            zujian.date = (TextView) convertView.findViewById(R.id.dateList);
            zujian.address = (TextView) convertView.findViewById(R.id.addressList);
            zujian.workContent = (TextView) convertView.findViewById(R.id.workContent);
            convertView.setTag(zujian);
        } else {
            zujian = (Zujian) convertView.getTag();
        }
        //绑定数据
        zujian.state.setText(list.get(position).get("Status").toString());
        zujian.title.setText(list.get(position).get("RepairCategory").toString());
        zujian.date.setText(list.get(position).get("HandleTime").toString());
        zujian.address.setText(list.get(position).get("RealAddress").toString());
        zujian.workContent.setText(list.get(position).get("ServiceContent").toString());

//        zujian.view.setOnClickListener(new View.OnClickListener(){
//            @Override
//            public void onClick(View v) {
//                Log.e("123","123");
//
//
//
//            }
//
//        });
//        zujian.image.setBackgroundResource((Integer)data.get(position).getImaged());
//        zujian.title.setText((String)data.get(position).getTextview1());
//        zujian.info.setText((String)data.get(position).getGetTextview12());
        return convertView;
    }

}
